package vip.xiaonuo.supplier.modular.setting.reports.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.pojo.CommonResult;
import vip.xiaonuo.supplier.modular.setting.reports.entity.PublicReports;
import vip.xiaonuo.supplier.modular.setting.reports.param.PublicReportsAddParam;
import vip.xiaonuo.supplier.modular.setting.reports.param.PublicReportsEditParam;
import vip.xiaonuo.supplier.modular.setting.reports.param.PublicReportsIdParam;
import vip.xiaonuo.supplier.modular.setting.reports.param.PublicReportsPageParam;
import vip.xiaonuo.supplier.modular.setting.reports.service.PublicReportsService;

import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import java.util.List;

/**
 * 打印格式控制器
 *
 * @author Mr.wu
 * @date  2025/04/01 15:08
 */
@Tag(name = "打印格式控制器")
@RestController
@Validated
public class PublicReportsController {

    @Resource
    private PublicReportsService publicReportsService;

    /**
     * 获取打印格式分页
     *
     * @author Mr.wu
     * @date  2025/04/01 15:08
     */
    @Operation(summary = "获取打印格式分页")
    @SaCheckPermission("/supplier/setting/reports/page")
    @GetMapping("/supplier/setting/reports/page")
    public CommonResult<Page<PublicReports>> page(PublicReportsPageParam publicReportsPageParam) {
        return CommonResult.data(publicReportsService.page(publicReportsPageParam));
    }

    /**
     * 添加打印格式
     *
     * @author Mr.wu
     * @date  2025/04/01 15:08
     */
    @Operation(summary = "添加打印格式")
    @CommonLog("添加打印格式")
    @SaCheckPermission("/supplier/setting/reports/add")
    @PostMapping("/supplier/setting/reports/add")
    public CommonResult<String> add(@RequestBody @Valid PublicReportsAddParam publicReportsAddParam) {
        publicReportsService.add(publicReportsAddParam);
        return CommonResult.ok();
    }

    /**
     * 编辑打印格式
     *
     * @author Mr.wu
     * @date  2025/04/01 15:08
     */
    @Operation(summary = "编辑打印格式")
    @CommonLog("编辑打印格式")
    @SaCheckPermission("/supplier/setting/reports/edit")
    @PostMapping("/supplier/setting/reports/edit")
    public CommonResult<String> edit(@RequestBody @Valid PublicReportsEditParam publicReportsEditParam) {
        publicReportsService.edit(publicReportsEditParam);
        return CommonResult.ok();
    }

    /**
     * 删除打印格式
     *
     * @author Mr.wu
     * @date  2025/04/01 15:08
     */
    @Operation(summary = "删除打印格式")
    @CommonLog("删除打印格式")
    @SaCheckPermission("/supplier/setting/reports/delete")
    @PostMapping("/supplier/setting/reports/delete")
    public CommonResult<String> delete(@RequestBody @Valid @NotEmpty(message = "集合不能为空")
                                                   List<PublicReportsIdParam> publicReportsIdParamList) {
        publicReportsService.delete(publicReportsIdParamList);
        return CommonResult.ok();
    }

    /**
     * 获取打印格式详情
     *
     * @author Mr.wu
     * @date  2025/04/01 15:08
     */
    @Operation(summary = "获取打印格式详情")
    @SaCheckPermission("/supplier/setting/reports/detail")
    @GetMapping("/supplier/setting/reports/detail")
    public CommonResult<PublicReports> detail(@Valid PublicReportsIdParam publicReportsIdParam) {
        return CommonResult.data(publicReportsService.detail(publicReportsIdParam));
    }
}
